#! /usr/bin/bash

while true; do
    cpu=$(vmstat 1 2 | tail -n1 | awk '{print 100-$15}')
    mem=$(free | awk 'NR==2 { printf("%.0f", (1-$7/$2)*100.0) }')
    bat=$(cat /sys/class/power_supply/BAT1/capacity)
    vol=$(amixer get Master | "$HOME"/opt/percent-reader)
    # vol=$(amixer get Master | grep -oE "(0|[1-9][0-9]*)%" | head -n1 | tr -d '%')

    on_ac_power=$(cat /sys/class/power_supply/ACAD/online)
    if [ "$on_ac_power" = 1 ]; then bat_icon="󰂄 "; else bat_icon="󱧥 "; fi
    if [ "$bat" -le 10 ]; then bat_alert="🆘🆘🆘🆘 "; else bat_alert=""; fi

    date=$(date +'  %A of Week %V, %Y-%m-%d |  %I:%M:%S %p')

    printf "󰱱  | $date | $bat_alert$bat_icon%3s%% | 󰕾 %3s%% | 󰍛 %3s%% |  %3s%% |" \
           "$bat" "$vol" "$mem" "$cpu"

    # NOTE: don't need this if we sample cpu load:
    # sleep 1
done
